package com.jingxing.controller;

import com.jingxing.config.ApiResult;
import com.jingxing.config.UserLoginToken;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@Slf4j
@RestController
@RequestMapping("/signUpReward")
@Api(value = "API", tags = {"奖品相关"})
@UserLoginToken
public class SignUpRewardController {
    @Autowired
    private RestTemplate restTemplate;

    private static final String URL_20001 = "http://JINGXINGPROJECT-SERVER";

    @PostMapping("/saveSignUpReward")
    @ApiOperation("添加奖品及领奖次数")
    @Transactional
    public ApiResult saveSignUpReward(String prizeName, Integer receiveSfrequency, String createBy) {
        MultiValueMap<String, Object> requestEntity = new LinkedMultiValueMap<>();
        requestEntity.add("prizeName", prizeName);
        requestEntity.add("receiveSfrequency", receiveSfrequency);
        requestEntity.add("createBy", createBy);
        return restTemplate.postForObject(URL_20001 + "/signUpReward/saveSignUpReward", requestEntity, ApiResult.class);
    }

    @PostMapping("/getSignUpRewards")
    @ApiOperation("获取奖品列表")
    public ApiResult getSignUpRewards(String prizeName) {
        MultiValueMap<String, Object> requestEntity = new LinkedMultiValueMap<>();
        requestEntity.add("prizeName", prizeName);
        return restTemplate.postForObject(URL_20001 + "/signUpReward/getSignUpRewards", requestEntity, ApiResult.class);
    }

    @PostMapping("/updateSignUpReward")
    @ApiOperation("修改奖品名称")
    public ApiResult updateSignUpReward(String id, String prizeName, String updateBy) {
        MultiValueMap<String, Object> requestEntity = new LinkedMultiValueMap<>();
        requestEntity.add("id", id);
        requestEntity.add("prizeName", prizeName);
        requestEntity.add("updateBy", updateBy);
        return restTemplate.postForObject(URL_20001 + "/signUpReward/updateSignUpReward", requestEntity, ApiResult.class);
    }

    @PostMapping("/delectSignUpReward")
    @ApiOperation("删除奖品及奖励领取")
    @Transactional
    public ApiResult delectSignUpReward(String id) {
        MultiValueMap<String, Object> requestEntity = new LinkedMultiValueMap<>();
        requestEntity.add("id", id);
        return restTemplate.postForObject(URL_20001 + "/signUpReward/delectSignUpReward", requestEntity, ApiResult.class);
    }


}
